add wechat publish record function #33
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
新增微信公众号统计功能
Description
新增完整的微信公众号文章统计分析功能,支持每日数据采集、多维度趋势分析和文章排行榜展示。该功能为内容运营团队提供数据驱动的决策支持,帮助评估文章表现、优化内容策略。
核心亮点:
Type of Change
Changes Made
数据模型层 (Models)
WechatArticleStat模型 - 文章每日统计快照表WechatStatsAggregate模型 - 多维度聚合统计表业务逻辑层 (Services)
WechatStatsService服务类 (app/services/wechat_stats.py)create_daily_stat()/batch_create_daily_stats()- 每日数据录入get_overview()- 统计概览 (总量、分类汇总、Top 10)get_trend()- 趋势数据 (可选周期/分类/日期范围)get_article_ranking()- 文章排行榜rebuild_aggregates()- 聚合数据重建update_article_category()- 批量更新文章分类API 路由层 (Routes)
app/api/wechat_stats.py路由模块GET /api/wechat-stats/overview- 获取统计概览GET /api/wechat-stats/trend- 获取趋势图表数据 (支持 6 种周期)GET /api/wechat-stats/ranking- 获取文章排行榜 (可按分类筛选)GET /api/wechat-stats/articles/{publish_record_id}/daily- 获取单篇文章每日统计PUT /api/wechat-stats/articles/{publish_record_id}/category- 更新文章分类POST /api/wechat-stats/daily- 录入单条每日统计POST /api/wechat-stats/daily/batch- 批量录入每日统计POST /api/wechat-stats/aggregates/rebuild- 重建聚合数据app/main.py中注册路由Schema 层 (Pydantic Models)
app/schemas/wechat_stats.pyWechatArticleStatOut- 每日统计输出WechatDailyStatCreate/WechatDailyStatBatchCreate- 统计数据录入WechatStatsAggregateOut- 聚合统计输出TrendResponse/TrendDataPoint- 趋势图表数据结构WechatStatsOverview/CategorySummary- 概览数据结构ArticleRankItem- 排行榜数据结构ArticleCategoryUpdate- 分类更新请求数据库变更
008_add_wechat_stats.pywechat_article_stats表 (12 个指标字段)wechat_stats_aggregates表 (聚合预计算)新增表结构
wechat_article_stats(文章每日统计表)索引:
ix_wechat_article_stats_publish_record_idix_wechat_article_stats_stat_dateix_wechat_article_stats_article_categoryix_wechat_article_stats_community_idix_wechat_stats_category_date(复合)ix_wechat_stats_community_date(复合)约束:
uq_article_stat_date(publish_record_id + stat_date)wechat_stats_aggregates(聚合统计表)索引:
ix_wechat_stats_aggregates_community_idix_wechat_stats_aggregates_period_typeix_wechat_stats_aggregates_period_startix_aggregate_period(复合: community_id + period_type + period_start)约束:
uq_stats_aggregate(community_id + period_type + period_start + article_category)Testing
Test Coverage
Test Instructions
测试覆盖场景